import Vue from 'vue';
import storage from '@js/storage';

export const state = () => ({
    webInfo: {}
})

export const getters = {
    webInfoData(state){
        let data = {};
        if(process.browser) {
            data = Object.keys(state.webInfo).length > 0 ? state.webInfo : storage.getSession('webInfo')
        }
        return data;
    }

};

export const mutations = {
    updateWebInfo(state , n){
        state.webInfo = n;
        storage.setSession('webInfo',n);
    }
}


export const actions = {
    getWebInfo(state){
    
        if(Object.keys(state.getters.webInfoData).length > 0) return 

        Vue.prototype.$get(state.getters['api/webinfo'].detail, data => {
            state.commit('updateWebInfo', data);
        });
    }
}

